using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Configurations;
using Sedna.Core.Controls.Support;
using ControlBuilder=Sedna.Core.Controls.Support.ControlBuilder;

namespace Sedna.Core.Controls
{
	/// <summary>
	/// Summary description for ValidatorContainer.
	/// </summary>
	public class ValidatorContainer: BaseControl
	{
		protected override HtmlTextWriterTag TagKey
		{
			get { return HtmlTextWriterTag.Span; }
		}

		public ValidatorContainer(IConfiguration configuration) : base(configuration)
		{
			Style.Add("overflow", "hidden");
		}

		protected override void Build()
		{
			base.Build();
			Width=Configuration.Width;
			IValidatorContainerConfiguration containerConfiguration=(IValidatorContainerConfiguration)configuration;
			if (containerConfiguration.Validators==null)
			{
				return;
			}
			foreach (IConfiguration validatorConfiguration in containerConfiguration.Validators)
			{
				WebControl control=(WebControl)ControlBuilder.BuildControl(validatorConfiguration);
				Controls.Add(control);
				control.Width=Width; //To prevent two validator to be visible simultaneously 
			}		
		}

//		protected override void Render(HtmlTextWriter writer)
//		{
//			//writer.Write("&nbsp;");
//			RenderBeginTag(writer);
//			writer.RenderBeginTag(HtmlTextWriterTag.Nobr);
//			RenderChildren(writer);
//			writer.RenderEndTag();
//			RenderEndTag(writer);
//		}

		protected override void RenderContents(HtmlTextWriter writer)
		{
			writer.RenderBeginTag(HtmlTextWriterTag.Nobr);
			base.RenderContents(writer);
			writer.RenderEndTag();
		}
	}
}
